package com.example.day2arouter.view;

import android.content.Context;
import android.os.Handler;
import android.widget.Toast;

import com.alibaba.android.arouter.facade.Postcard;
import com.alibaba.android.arouter.facade.annotation.Interceptor;
import com.alibaba.android.arouter.facade.callback.InterceptorCallback;
import com.alibaba.android.arouter.facade.template.IInterceptor;
import com.alibaba.android.arouter.launcher.ARouter;

import static com.example.day2arouter.view.Path.DATA;
import static com.example.day2arouter.view.Path.INTERCEPTOR;

@Interceptor(priority = 9)
public class MyInterceptor implements IInterceptor {
   private   boolean isLogin=false;
    @Override
    public void process(Postcard postcard, InterceptorCallback callback) {
        String path = postcard.getPath();
        switch (path){
            case "/app_modules/InterceptorActivity":
                //拦截
                if(isLogin){
                    callback.onContinue(postcard);
                }else{
                    callback.onInterrupt(new Throwable("你被打劫了"));
                    ARouter.getInstance().build(DATA)
                            .withString("name","涂山苏苏")
                            .withInt("age",500)
                            .navigation();
                }
                break;
                default:
                //交还
                callback.onContinue(postcard);
                break;
        }
    }

    @Override
    public void init(Context context) {

    }
}
